//
//  SessionManager.swift
//  NetWork
//
//  Created by Delin Meng 孟德林 on 2018/7/30.
//  Copyright © 2018年 Delin Meng 孟德林. All rights reserved.
//

import UIKit

open class SessionManager: NSObject {

    public enum MultipartFormDataEncodingRequest {
        
        case success(request: URLRequest,streamingFromDisk:Bool,StreamFileURL:URL?)
        case failure(Error)
        
    }
    
    static let `default`:SessionManager = {
        let configuration = URLSessionConfiguration.default
        return SessionManager()
    }()

//    static let defaultHTTPHeaders
    
    open static let multipartFromDataEncodingMemoryThreshold:UInt64 = 10_000_000
    
    let session:URLSession
    
    var startRequestsImmediately:Bool = true
    
    /// 请求适配
    /// 请求重试
    
    var backgroupCompletionHandler:(()->Void)?
    let queue = DispatchQueue(label: "org.alamofire.session-manager." + UUID().uuidString)
    
    
    
    public init(configuration:URLSessionConfiguration = URLSessionConfiguration.default) {
        self.session = URLSession.init(configuration: configuration, delegate: nil, delegateQueue: nil)
        
    }
    
    deinit {
        session.invalidateAndCancel()
    }
    
    
 /// 网络请求
    
    @discardableResult
    func request(_ url:URL,
                 method:String = "get",
                 parameters:[String: Any],
                 headers:[String:String]
        ) -> URLRequest {
        
        var originalRequest: URLRequest?
        do {
            originalRequest = URLRequest.init(url: url)
            originalRequest?.httpMethod =  method
            originalRequest?.allHTTPHeaderFields = headers
            return originalRequest!
            
        } catch {

            return URLRequest(url: url)

        }
        
    }
    
    
    @discardableResult
    func request(_ request:URLRequest) -> URLRequest {
        
        var originalRequest:URLRequest?
        originalRequest = request
        return originalRequest!
        
    }
    
    
        
    
    
    
    
    
    
}
